<!--
Copyright 2013 The Polymer Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
<!--
/**
 * @module Polymer Elements
 */
/**
 * polymer-meta is used to manage metadata.  When an instance of polymer-meta
 * is created, it's automatically registered and add to the metaData storage given an id
 * is set on the element. Use byId() to retrive a specific polymer-meta and
 * the property "list" to retrieve all registered polymer-meta's.
 *
 * @class polymer-meta
 */
-->
<polymer-element name="polymer-meta" attributes="list label">
  <script>
    (function() {
      var SKIP_ID = 'meta';
      var metaData = {}, metaArray = [];

      Polymer('polymer-meta', {
        ready: function() {
          this.idChanged();
        },
        idChanged: function(old) {
          if (this.id && this.id !== SKIP_ID) {
            this.unregister(this, old);
            metaData[this.id] = this;
            metaArray.push(this);
          }
        },
        unregister: function(meta, id) {
          delete metaData[id || meta.id];
          var i = metaArray.indexOf(meta);
          if (i >= 0) {
            metaArray.splice(i, 1);
          }
        },
        get list() {
          return metaArray;
        },
        get archetype() {
          return this.querySelector('template');
        },
        byId: function(id) {
          return metaData[id];
        }
      });
    })();
  </script>
</polymer-element>
